<script type="text/javascript">
	
function TreeNode(x) {
    this.val = x;
    this.left = null;
    this.right = null;
}
let a = new TreeNode(1);
let b = new TreeNode(2);
let c = new TreeNode(3);
let d = new TreeNode(4);
let e = new TreeNode(5);
let f = new TreeNode(6);
let g = new TreeNode(7);
a.left = b;
a.right = c;
b.left = d;
b.right = e;
c.left = f;
c.right = g;


function PrintFromTopToBottom(root)
{
	let res = [];
    if (!root) return res;
    let arr = [root];
    let res = [];
    while(arr.length) {
        res.push(arr[0].val);
        arr[0].left ? arr.push(arr[0].left) : '';
        arr[0].right ? arr.push(arr[0].right) : '';
        arr.shift();
    }
    return res;
}

const res = PrintFromTopToBottom(a);
console.log(res);

</script>